package com.woniu.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.entity.RechargeRecord;
import com.woniu.service.RechargeRecordService;
import com.woniu.mapper.RechargeRecordMapper;
import com.woniu.vo.RechargeRecordVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Apricity
* @description 针对表【recharge_record(充值记录表)】的数据库操作Service实现
* @createDate 2025-02-13 20:16:59
*/
@Service
public class RechargeRecordServiceImpl extends ServiceImpl<RechargeRecordMapper, RechargeRecord>
    implements RechargeRecordService {

    @Resource
    private RechargeRecordMapper rechargeRecordMapper;

    @Override
    public List<RechargeRecordVO> getRechargeRecordList(String keyword, Integer pageNum, Integer pageSize) {
        Page<RechargeRecordVO> page = new Page<>(pageNum, pageSize);
        List<RechargeRecordVO> records;
        
        if (keyword != null && !keyword.trim().isEmpty()) {
            records = rechargeRecordMapper.queryRechargeRecordByKeyword(keyword, page);
        } else {
            records = rechargeRecordMapper.queryRechargeRecordList(page);
        }
        
        return records;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addRechargeRecord(RechargeRecord rechargeRecord) {
        return rechargeRecordMapper.insert(rechargeRecord) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteRechargeRecord(Long id) {
        return rechargeRecordMapper.deleteById(id) > 0;
    }
}




